<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/19
 * Time: 9:25
 */
require 'config.php';
$name = $_POST['name'];
$auth = $_POST['auth'];
if($_POST['aa'] == '1'){

        $sql = "select * from user where userName = '$name'";
        $result = mysqli_query($link,$sql);
        $rows = mysqli_fetch_assoc($result);
        $time = $rows['expired'];
        $time1 = date('Y-m-d',strtotime("$time +1 month"));
        $sql = "update user set expired ='$time1' where userName = '$name'";
        mysqli_query($link,$sql);
        if (mysqli_affected_rows($link)>0){
            echo json_encode(array('name'=>$time1));
        }else{
            echo "<script>alert('充值失败');window.location.href='./vip.php';</script>";die;
        }
        mysqli_free_result($result);
        mysqli_close($link);

}
if ($_POST['aa'] == '3'){

        $sql = "select * from user where userName = '$name'";
        $result = mysqli_query($link,$sql);
        $rows = mysqli_fetch_assoc($result);
        $time = $rows['expired'];
        $time1 = date('Y-m-d',strtotime("$time +3 month"));
        $sql = "update user set expired ='$time1' where userName = '$name'";
        mysqli_query($link,$sql);
        if (mysqli_affected_rows($link)>0){
            echo json_encode(array('name'=>$time1));
        }else{
            echo "<script>alert('充值失败');window.location.href='./vip.php';</script>";die;
        }
        mysqli_free_result($result);
        mysqli_close($link);

}
if ($_POST['aa'] == '6'){

        $sql = "select * from user where userName = '$name'";
        $result = mysqli_query($link,$sql);
        $rows = mysqli_fetch_assoc($result);
        $time = $rows['expired'];
        $time1 = date('Y-m-d',strtotime("$time +6 month"));
        $sql = "update user set expired ='$time1' where userName = '$name'";
        mysqli_query($link,$sql);
        if (mysqli_affected_rows($link)>0){
            echo json_encode(array('name'=>$time1));
        }else{
            echo "<script>alert('充值失败');window.location.href='./vip.php';</script>";die;
        }
        mysqli_free_result($result);
        mysqli_close($link);

}

if ($_POST['aa'] == '12'){

        $sql = "select * from user where userName = '$name'";
        $result = mysqli_query($link,$sql);
        $rows = mysqli_fetch_assoc($result);
        $time = $rows['expired'];
        $time1 = date('Y-m-d',strtotime("$time +12 month"));
        $sql = "update user set expired ='$time1' where userName = '$name'";
        mysqli_query($link,$sql);
        if (mysqli_affected_rows($link)>0){
            echo json_encode(array('name'=>$time1));
        }else{
            echo "<script>alert('充值失败');window.location.href='./vip.php';</script>";die;
        }
        mysqli_free_result($result);
        mysqli_close($link);

}
